//const baseUrl = 'https://1.zzqifan.cn/api'
const baseUrl = 'https://le.bjxlu.com'
//const baseUrl = 'https://cheng.wuhewan.com/api'
 

const request = (options) => {
	return new Promise((resolve, reject) => {
		 // console.log('options.url',options.url)
		 // console.log('optionsdata',options.data)
		let header = {}
		if(uni.getStorageSync('token')){
			header.Authorization = uni.getStorageSync('token')
		} 
		uni.request({
			method: options.method??'POST',
			url: baseUrl + options.url,
			data: options.data??{},
			header,
			dataType: 'json',
		}).then((response) => {
			const { data } = response;   
			if(response.statusCode == 500){
				uni.showToast({
					title: "系统错误", 
					icon: "none", 
				})
			}else if(response.statusCode == 200){
			    if(data.code == 200){
					resolve(data.data)
				}else if(data.code == 401){
					uni.reLaunch({
						url:"/pages/user/login"
					}) 
				}else{
					uni.showToast({
						title:data.message,
						icon: "none", 
					})
				}
			} else if(response.statusCode == 401){
			   uni.reLaunch({
					url:"/pages/user/login"
			   }) 
			} 
		}).catch(error => {
			uni.showToast({
				title: "系统错误",
				icon: "none", 
			})
			reject(error)
			console.log('error',error)  
		})
	});
}
export default request